package leecode

func rob(nums []int) (result int) {
	if len(nums) < 2 {
		return nums[0]
	}

	dp := make([]int, len(nums)) //走到第i间房子能偷盗的最大值
	dp[0] = nums[0]
	dp[1] = max(nums[0], nums[1])
	result = dp[1]
	for i := 2; i < len(nums); i++ {
		dp[i] = max(dp[i-2]+nums[i], dp[i-1])
		temp := dp[i]
		if temp > result {
			result = temp
		}
	}
	return
}
